import {
  closeUnpayExpiredOrders,
  closeEndedActivities,
  settleProfitedOrders,
  sendCheckIn1RemindNotifications,
  submitOrderProfitShareAtAfterSaleDeadline,
  retryNsqFail,
} from "../../service/cronService";
import Router from "koa-router";
const router = new Router();

router.post("/_cmd/cron/closeUnpayExpiredOrders", async (ctx, next) => {
  const { limit } = ctx.request.body;
  let success = await closeUnpayExpiredOrders(limit);
  ctx.body = success;
});

router.post("/_cmd/cron/closeEndedActivities", async (ctx, next) => {
  const { limit } = ctx.request.body;
  let success = await closeEndedActivities(limit);
  ctx.body = success;
});

router.post("/_cmd/cron/settleProfitedOrders", async (ctx, next) => {
  const { limit } = ctx.request.body;
  let success = await settleProfitedOrders(limit);
  ctx.body = success;
});

router.post("/_cmd/cron/sendCheckIn1RemindNotifications", async (ctx, next) => {
  const { limit } = ctx.request.body;
  let success = await sendCheckIn1RemindNotifications(limit);
  ctx.body = success;
});

router.post(
  "/_cmd/cron/submitOrderProfitShareAtAfterSaleDeadline",
  async (ctx, next) => {
    const { limit } = ctx.request.body;
    let success = await submitOrderProfitShareAtAfterSaleDeadline(limit);
    ctx.body = success;
  }
);

router.post("/_cmd/cron/retryNsqFail", async (ctx, next) => {
  const { limit } = ctx.request.body;
  let success = await retryNsqFail(limit);
  ctx.body = success;
});

export default router;
